import CryptoJS from 'crypto-js'
// CBC 模式
//加密
function setDES(message) {
  var keyHex = CryptoJS.enc.Utf8.parse('5RkLWI/aWIU+wumb1UmR/eUZC1iP2liF');
  var ivHex = CryptoJS.enc.Utf8.parse("desede/CBC/PKCS5Padding");
  encrypted = CryptoJS.DES.encrypt(message, keyHex, {
      iv:ivHex,
      mode: CryptoJS.mode.CBC,
      padding:CryptoJS.pad.Pkcs7
    }
  );
  // return encrypted.ciphertext.toString();
  console.log( encrypted.ciphertext.toString(CryptoJS.enc.Base64));
  return encrypted.ciphertext.toString(CryptoJS.enc.Base64);

}
//解码
export function setDES(ciphertext2) {
// 后台拿的密文，解不出来
var ciphertext2 ="6U766eMjv1nORfdE1apW96D9W8+vXkddAtpzpd6+gWlnKRcP4XEIqy1m1AgSzGbuzGW2o35vlIhim9Be1S1hDzmmzKEs9YrR4INM0J3+VYI=";
var keyHex = CryptoJS.enc.Utf8.parse('5RkLWI/aWIU+wumb1UmR/eUZC1iP2liF');
var ivHex = CryptoJS.enc.Utf8.parse("desede/CBC/PKCS5Padding");
// direct decrypt ciphertext
var decrypted = CryptoJS.DES.decrypt({
ciphertext: CryptoJS.enc.Base64.parse(ciphertext2)
}, keyHex, {
iv:ivHex,
mode: CryptoJS.mode.CBC,
padding: CryptoJS.pad.Pkcs7
});
console.log(decrypted.toString(CryptoJS.enc.Utf8))
return decrypted.toString(CryptoJS.enc.Utf8);
}
